<template>
	<div>
    <Content>
      <Form inline>
        <FormItem>
          <Input style="width: 400px" v-model="keywords" search enter-button placeholder="请输入关键字" @on-search="searchGet" @submit.native.prevent/>
        </FormItem>
        <FormItem>
          <Button @click="reset">重置</Button>
        </FormItem>
      </Form>
      <Table border :columns="columns" :data="dataGrid"></Table>
      <HigPager v-model="query" :total="pageTotal" :init="Init"></HigPager>
    </Content>
  </div>
</template>
<script scope>
import defUserImage from '@/images/def-head.png'
export default {
  data () {
    return {
      pageTotal: 0,
      keyIndex: 0,
      dataGrid:[],
      regionArray: [],
      keywords: null,
      showInsertVue: false,
      showEditVue: false,
      showUpdateVue: false,
      query: {
        pageIndex: 1,
        pageSize: 15,
        equal: {},
      },
      columns: [
        {
          title: "头像",
          key: "userImage",
          width: 110,
          render: (h, params) => {
            return h("div", [
              h("img",{
                  attrs: {src: params.row.userImage},
                  style: {width: "60px",height: "60px",marginTop:"8px"},
                },
              ),
            ])
          },
        },
        {
          title: "会员名称",
          key: "userName",
        },
        {
          title: "联系电话",
          key: "unionMobile",
        },
        {
          title: "加入时间",
          key: "postTime",
          width: 180,
          render: (h, params) => {
            return h("div", this.$date(params.row.postTime,'yyyy-MM-dd HH:mm'));
          },
        },
      ]
    }
  },
  methods: {
    //获取列表
    Init(srvGroupId){
      if(srvGroupId) {
        this.query.equal.srvGroupId = srvGroupId
      }
      
      new this.$rest({
        gateway: 'agrobiz',
        service: 'agrobiz-uc',
        url: '/v1.0/view/union/user/plus/page',
        query: this.query,
        action: (res) => {
          if (res.data.code === 20000) {
            this.pageTotal = res.data.data.count
            this.dataGrid = res.data.data.list
            for(let item of this.dataGrid) {
              item.userName = item.userName ? item.userName : '匿名用户'
              item.unionMobile = this.$phone(item.unionMobile)
              item.userImage = item.userImage ? item.userImage : defUserImage
            }
          } else {
            this.$Message.error(res.data.msg)
          }
        }
      }).get()
     },
     //搜索
    searchGet() {
      let sqlLike = {
        fields: ["user_name","union_mobile","nick_name"],
        keyword: this.keywords,
      }
      this.query.sqlLike = sqlLike
      this.query.pageIndex = 1
      this.Init()
    },
    //重置
    reset() {
      delete this.query.sqlLike
      this.keywords = null
      this.Init()
    }
  },
}
</script>
<style lang="less" scoped>
.imgs {
  width: 80%;
}
</style>